//
//  WHSettingCell.m
//  SquirrelSeller
//
//  Created by 邓伟浩 on 2019/1/6.
//  Copyright © 2019 邓伟浩. All rights reserved.
//

#import "WHSettingCell.h"

@interface WHSettingCell ()

@property (nonatomic, strong) UIButton *switchBtn;

@end

@implementation WHSettingCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setUpUI];
    }
    return self;
}

- (void)setUpUI {
    [self.contentView addSubview:({
        _tipsLabel = [[UILabel alloc] init];
        _tipsLabel.font = SYSTEMFONT(kRealwidth(16));
        _tipsLabel.textColor = CFontTitleBlackColor;
        _tipsLabel;
    })];
    [_tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left).offset(kRealwidth(15));
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.height.mas_equalTo(kRealwidth(16));
    }];
    
    [self.contentView addSubview:({
        _switchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _switchBtn;
    })];
    [_switchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.contentView.mas_right).offset(-kRealwidth(15));
        make.width.mas_equalTo(kRealwidth(60));
        make.height.mas_equalTo(35);
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
    }];
    [_switchBtn addTarget:self action:@selector(switchBtnClicked) forControlEvents:UIControlEventTouchUpInside];
}

- (void)setIsOpen:(BOOL)isOpen {
    _isOpen = isOpen;
    
    if (isOpen) {
        [_switchBtn setImage:IMAGE_NAMED(@"setting_isOpen") forState:UIControlStateNormal];
    } else {
        [_switchBtn setImage:IMAGE_NAMED(@"setting_isClose") forState:UIControlStateNormal];
    }
}

- (void)switchBtnClicked {
    if (self.switchClicked) {
        self.switchClicked();
    }
}


@end
